var app = angular.module('morningconferenceList', []);
app.controller('listController', function ($scope,$http) {

    $scope.addType = "";
    hasNextDayInfo();


    function initDate(date){
        $('#manage').html(currentTime(date));
        $('#datetimepicker11').datetimepicker({
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            //todayHighlight: 1,
            startView: 2,//开始视图
            minView: 2,//最小层级视图
            forceParse: 0,
            inline: true,
            sideBySide: true,
            initialDate:date,
            format:'yyyy-MM-dd',
        }).on('changeDate',function(ev){
            getData(ev.date);
        });
    }

    function getData(date) {
        date = typeof (date) =='undefined'?new Date():date;
        $http.get("/smtool_project/api/morningconference/getMorningconferenceByDate",{
            params: {
                "status":"1",
                "date":date.format("yyyy-MM-dd")
            }
        }).then(function (result) {
            $scope.datas = result?result.data.obj:[];
            $scope.stockVals = result?result.data.stockVals:"";
            $scope.nums = new Array($scope.datas.length);
        });
    };
    function hasNextDayInfo(){
        var date = new Date();
        date.setDate(date.getDate()+1);
        $http.get("/smtool_project/api/morningconference/getMorningconferenceByDate",{
            params: {
                "status":"1",
                "date":date.format("yyyy-MM-dd"),
            }
        }).then(function (result) {
            var putDate =  result&&result.data.obj.length>0?date:new Date();
            initDate(putDate);
            getData(putDate);
        });
    };
    $scope.allData = function(addType) {
        $scope.addType = addType||'';
        getData(addType);
    };
    $scope.toDetail = function(rowId){
        location.href = "morningconferencedetail?rowId="+rowId;
    };
    function currentTime(currentDate){
        // var curentDay=currentDate.getDay();
        // var currentHour=currentDate.getHours();
        // if(curentDay==6){
        //     currentDate.setDate(currentDate.getDate()+2);
        // }else if(curentDay==0){
        //
        //     currentDate.setDate(currentDate.getDate()+1);
        // }
        // else if(currentHour>=12){
        //
        //     currentDate.setDate(currentDate.getDate()+1);
        // }

        str='';
        str+=currentDate.getFullYear()+'年';
        str+=currentDate.getMonth() + 1+'月';
        str+=currentDate.getDate()+'日';
        str+=" "+getweek(currentDate);
        return str;
    }

    function getweek(currentDate){
        var show_day=new Array('星期一','星期二','星期三','星期四','星期五','星期六','星期日');

        var day=currentDate.getDay();
        if(day==0){
            day=6
        }else{
            day=day-1
        }
        return show_day[day];
    }
});
app.filter('getRealPercent',function(){
    return function(val,importPrice) {
        var realRate = getRealRate(importPrice, val);
        return toDecimal(realRate) + "%";
    }
    function getRealRate(importPrice, realPrice) {
        return (realPrice - importPrice) * 100 / importPrice
    };
    function toDecimal(x) {
        var f = parseFloat(x);
        if (isNaN(f)) {
            return;
        }
        f = Math.round(x * 100) / 100;
        return f;
    };
})
